home *** CD-ROM | disk | FTP | other *** search
- /*
- Tests of declarations that SPP must handle cleanly.
-
- source: dcltest.c
- started: April 4, 1988
- version:
- February 17, 1989
- March 24, 1989 struct test added
- June 27, 1989
- second struct test added
- nested comment test added
- macro overflow test added
- regression tests added
- August 4, 1989
- union b changed to union bb.
- */
-
- #include "\sherlock\sl.h"
-
- struct a {int sa;};
- struct b {int sb;};
- union bb {int sb;};
-
- /* Old style. */
- int types1A(
- c, sc, uc, sh, ssh, shi, sshi,
- ac, asc, auc, ash, assh, ashi, asshi)
- char c;
- signed char sc;
- unsigned char uc;
- short sh;
- signed short ssh;
- short int shi;
- signed short int sshi;
- char ac[1];
- signed char asc[];
- unsigned char auc[10000];
- short ash[];
- signed short assh[2];
- short int ashi[];
- signed short int asshi[100];
- {
- printf("(%c, %c, %c, %d, %d, %d, %d)\n",
- c, sc, uc, sh, ssh, shi, sshi);
- printf("(%p, %p, %p, %p, %p, %p, %p)\n",
- ac, asc, auc, ash, assh, ashi, asshi);
- }
-
- /* New style. */
- int types1B(
- char c,
- signed char sc,
- unsigned char uc,
- short sh,
- signed short ssh,
- short int shi,
- signed short int sshi,
- char ac[2],
- signed char asc[3],
- unsigned char auc[],
- short ash[4],
- signed short assh[5],
- short int ashi[],
- signed short int asshi[])
- {
- printf("(%c, %c, %c, %d, %d, %d, %d)\n",
- c, sc, uc, sh, ssh, shi, sshi);
- printf("(%p, %p, %p, %p, %p, %p, %p)\n",
- ac, asc, auc, ash, assh, ashi, asshi);
- }
-
- /* Direct typedefs. */
- typedef char tc;
- typedef int ti;
- typedef short tsh;
-
- typedef signed char tsc;
- typedef unsigned char tuc;
- typedef signed short tssh;
- typedef short int tshi;
- typedef signed short int tsshi;
-
- /* Multi-level typedefs. */
- typedef signed tc tstc;
- typedef unsigned tc tutc;
- typedef signed tsh tstsh;
- typedef short ti tshti;
- typedef signed short ti tsshti;
-
- typedef short ti * tshtip;
- typedef tsshti * tsshtip;
-
- /* Old style with typedefs. */
- tssh types1C( c, sc, stc, uc, utc, sh, ssh, stsh,
- shi, shti, sshi, sshti, shtip, sshtip,
- ac, asc, astc, auc, autc, ash, assh, astsh,
- ashi, ashti, asshi, asshti, ashtip, asshtip)
- tc c, ac[1];
- tsc sc, asc[2]; tstc stc, astc[];
- tuc uc, auc[]; tutc utc, autc[3];
- tsh sh, ash[4];
- tssh ssh, assh[]; tstsh stsh, astsh[5];
- tshi shi, ashi[6]; tshti shti, ashti[7];
- tsshi sshi, asshi[]; tsshti sshti, asshti[];
- tshtip shtip, ashtip[100];
- tsshtip sshtip, asshtip[101];
- {
- printf("(%c, %c, %c, %c, %c, %d, %d, %d, %d, %d, %d, %d, %p, %p)\n",
- c, sc, stc, uc, utc,
- sh, ssh, stsh, shi, shti,
- sshi, sshti, shtip, sshtip);
- printf("(%p, %p, %p, %p, %p, %p, %p, %p, %p, %p, %p, %p, %p, %p)\n",
- ac, asc, astc, auc, autc,
- ash, assh, astsh, ashi, ashti,
- asshi, asshti, ashtip, asshtip);
-
- return 1;
- }
-
- /* New style with typedefs. */
- tsshi types1D(
- tc c,
- tsc sc,
- tuc uc,
- tsh sh,
- tssh ssh,
- tshi shi,
- tsshi sshi)
- {
- printf("(%c, %c, %c, %d, %d, %d, %d)\n",
- c, sc, uc, sh, ssh, shi, sshi);
-
- return 1;
- }
-
- /* Old Style. */
- int types2A(ush, ushi, i, s, si, u, ui)
- unsigned short ush;
- unsigned short int ushi;
- int i;
- signed s;
- signed int si;
- unsigned u;
- unsigned int ui;
- {
- printf("(%u, %u, %d, %d, %d, %u, %u)\n",
- ush, ushi, i, s, si, u, ui);
- }
-
- /* New Style. */
- int types2B(
- unsigned short ush,
- unsigned short int ushi,
- int i,
- signed s,
- signed int si,
- unsigned u,
- unsigned int ui)
- {
- printf("(%u, %u, %d, %d, %d, %u, %u)\n",
- ush, ushi, i, s, si, u, ui);
- }
-
- typedef unsigned short tush;
- typedef unsigned short int tushi;
- typedef signed ts;
- typedef signed int tsi;
- typedef unsigned tu;
- typedef unsigned int tui;
-
- /* Old Style with typedefs */
- tush types2C(ush, ushi, i, s, si, u, ui)
- tush ush;
- tushi ushi;
- ti i;
- ts s;
- tsi si;
- tu u;
- tui ui;
- {
- printf("(%u, %u, %d, %d, %d, %u, %u)\n",
- ush, ushi, i, s, si, u, ui);
-
- return 0xffff;
- }
-
- /* New Style with typedefs */
- tushi types2D(
- tush ush,
- tushi ushi,
- ti i,
- ts s,
- tsi si,
- tu u,
- tui ui)
- {
- printf("(%u, %u, %d, %d, %d, %u, %u)\n",
- ush, ushi, i, s, si, u, ui);
-
- return 0xffff;
- }
-
-
- /* Old Style. */
- unsigned types3A(l, sl, li, sli, ul, uli)
- long l;
- signed long sl;
- long int li;
- signed long int sli;
- unsigned long ul;
- unsigned long int uli;
- {
- printf("(%ld, %ld, %ld, %ld, %lu, %lu)\n",
- l, sl, li, sli, ul, uli);
-
- return 0xffff;
- }
-
- /* New Style. */
- unsigned long types3B(
- long l,
- signed long sl,
- long int li,
- signed long int sli,
- unsigned long ul,
- unsigned long int uli)
- {
- printf("(%ld, %ld, %ld, %ld, %lu, %lu)\n",
- l, sl, li, sli, ul, uli);
-
- return 0xffffffff;
- }
-
- typedef long tl;
- typedef signed long tsl;
- typedef long int tli;
- typedef signed long int tsli;
- typedef unsigned long tul;
- typedef unsigned long int tuli;
-
- /* Old Style with typedefs. */
- tul types3C(l, sl, li, sli, ul, uli)
- tl l;
- tsl sl;
- tli li;
- tsli sli;
- tul ul;
- tuli uli;
- {
- printf("(%ld, %ld, %ld, %ld, %lu, %lu)\n",
- l, sl, li, sli, ul, uli);
-
- return 0xffffffff;
- }
-
- /* New Style with typedefs. */
- tuli types3D(
- tl l,
- tsl sl,
- tli li,
- tsli sli,
- tul ul,
- tuli uli)
- {
- printf("(%ld, %ld, %ld, %ld, %lu, %lu)\n",
- l, sl, li, sli, ul, uli);
-
- return 0xffffffff;
- }
-
- /* Old Style. */
- float types4A(f, d, ld, st, un, e)
- float f;
- double d;
- long double ld;
- struct a st;
- union bb un;
- enum en e;
- {
- printf("(%g, %g, %g, %p, %p, %d)\n",
- f, d, ld, st, un, e);
-
- printf("=(%p, %p)\n", &st, &un); /* 3/24/89 */
-
- return (float) 0.0;
- }
-
- /* New Style. */
- double types4B(
- float f,
- double d,
- long double ld,
- struct a st,
- union bb un,
- enum en e)
- {
- printf("(%g, %g, %g, %p, %p, %d)\n",
- f, d, ld, st, un, e);
-
- printf("=(%p, %p)\n", &st, &un); /* 3/24/89 */
-
- return (double) 0.0;
- }
-
- typedef float tf;
- typedef double td;
- typedef long double tld;
- typedef struct a tst;
- typedef union bb tun;
- typedef enum en te;
-
- /* Old Style with typedefs. */
- tf types4C(f, d, ld, st, un, e)
- tf f;
- td d;
- tld ld;
- tst st;
- tun un;
- te e;
- {
- printf("(%g, %g, %g, %p, %p, %d)\n",
- f, d, ld, st, un, e);
-
- return 0.1;
- }
-
- /* New Style with typedefs. */
- td types4D(
- tf f,
- td d,
- tld ld,
- tst st,
- tun un,
- te e)
- {
- printf("(%g, %g, %g, %p, %p, %d)\n",
- f, d, ld, st, un, e);
-
- return (double) 0.1;
- }
-
- /* Old Style. */
- char * types5A(c, s, p)
- char c;
- char * s;
- char ** p;
- {
- printf("(%c, %s, %p)\n", c, s, p);
-
- return "abc";
- }
-
- /* New Style. */
- char ** types5B(
- char c,
- char * s,
- char ** p)
- {
- printf("(%c, %s, %p)\n", c, s, p);
-
- return ((char **) 0);
- }
-
- typedef tc * string1;
- typedef char * string2;
- typedef string1 * tcpp1;
- typedef char ** tcpp2;
-
- /* Old Style. */
- string1 types5C(c, s1, s2, p1, p2)
- tc c;
- string1 s1;
- string2 s2;
- tcpp1 p1;
- tcpp2 p2;
- {
- printf("(%c, %s, %s, %p, %p)\n", c, s1, s2, p1, p2);
-
- return "abc";
- }
-
- /* New Style. */
- tcpp1 types5D(
- tc c,
- string1 s1,
- string2 s2,
- tcpp1 p1,
- tcpp2 p2)
- {
- printf("(%c, %s, %s, %p, %p)\n", c, s1, s2, p1, p2);
-
- return ((char **) 0);
- }
-
- typedef int ta [25];
- typedef ta * tap;
-
- /* Old Style. */
- ta * types6A(a, ap1, ap2)
- ta a;
- tap ap1;
- ta * ap2;
- {
- printf("(%p, %p, %p)\n", a, ap1, ap2);
-
- return (ta *) 0;
- }
-
- /* New Style. */
- ta * types6B(
- ta a,
- tap ap1,
- ta * ap2)
- {
- printf("(%p, %p, %p)\n", a, ap1, ap2);
-
- return (ta *) 0;
- }
-
- int a20;
- int * types7(void)
- {
- return &a20;
- }
-
- int types8(int (* func)(void))
- {
- printf("%p", func);
-
- return 1;
- }
-
- typedef int bool;
- typedef bool bool2;
-
- bool types9A(b1)
- bool b1;
- {
- printf("(%d)\n", b1);
- return 1;
- }
-
- bool2 type9B(bool b1, bool2 b2)
- {
- printf("(%d, %d)\n", b1, b2);
- return 1;
- }
-
- enum hue {chartreuse, burgundy, claret=20, winedark};
- enum hue types9(void)
- {
- return chartreuse;
- }
-
- /*
- More tests of weird and wonderful declarations.
- See pages 244 and 245 of Turbo C User's Guide.
- */
-
- /* Page 244. */
- int f1();
- int * p1;
- int *f2();
- int far *p2;
- int far *f3();
- int *far f4();
- int (*fp1) (int);
- int (*fp2) (int *ip);
- int (far *fp3) (int far *ip);
- int (far *list[5]) (int far *ip);
- int (far *gopher(int (far * fp[5]) (int far * ip))) (int far *ip);
-
- /* Page 245. */
- int f1();
- typedef int *intptr;
- intptr p1;
- typedef int far * farptr;
- farptr p2;
- typedef int (fncptr1) (int);
- fncptr1 fp10;
- typedef int (*fncptr2) (intptr);
- fncptr2 fp11;
- typedef int (far *ffptr) (farptr);
- ffptr fp12;
- typedef ffptr ffplist [5];
- ffplist list;
- ffptr gopher(ffplist);
-
- int fv(void), *fip(), (*pfi)();
- int (*fpfi(int(*)(long), int))(int,...);
- int (*apfi[3]) (int *x, int *y);
-
- /* Array modifications from page 244. */
- int * ap1 [10];
- int (* pa1) [11];
- int (*afp1) (int[]);
- int (*afp2) (int *ip[4]);
- int (*alist[5]) (int far *aip[5]);
- int (far *agopher(int (far * fp[5]) (int far * ip[]))) (int far *ip[8]);
-
- /* Array modifications from page 245. */
- typedef int * aintptr[20];
- aintptr ap1A[2];
- typedef int far * afarptr[3];
- afarptr ap2;
- typedef int (*afncptr1[25]) (int[]);
- afncptr1 afp10;
- typedef int (*afncptr2) (aintptr[]);
- afncptr2 afp11[26];
- typedef int (far *affptr) (afarptr[]);
- affptr afp12[27];
- typedef ffptr affplist [5];
- affplist a2list[28];
- affptr a2gopher(affplist[]);
-
- /* 6/22/89 */
- void fred(int []);
- struct fred2 {int i; int v[3];};
- struct fred2 t = {1, {0,0,0}};
-
- /* 6/27/89 */
- struct s {int i; char v[3];};
- struct s t1;
- typedef struct s tstruct;
-
- /* Old Style */
- struct s
- struct_testA(t2, t3, t4, t5, at1, at2)
- struct s t2, *t3;
- tstruct t4, *t5;
- struct s at1[2];
- tstruct at2[3];
- {
- printf("%p, %p, %p, %p, %p %p\n", &t2, t3, &t4, t5, at1, at2);
- return t1;
- }
-
- /* New Style */
- struct s
- struct_testB(
- struct s t2,
- struct s *t3,
- tstruct t4,
- tstruct *t5,
- struct s at1[],
- tstruct at2[])
- {
- printf("%p, %p, %p, %p, %p, %p\n", &t2, t3, &t4, t5, at1, at2);
- return t1;
- }
-
- /* Old Style with typedefs */
- tstruct
- struct_testA2(t2, t3, t4, t5)
- tstruct t2, *t3;
- struct s *t4, t5;
- {
- printf("%p, %p, %p, %p\n", &t2, t3, t4, &t5);
- return t1;
- }
-
- /* New Style with typedefs */
- tstruct
- struct_testB2(
- tstruct t2,
- tstruct *t3,
- struct s *t4,
- struct s t5)
- {
- printf("%p, %p, %p, %p\n", &t2, t3, t4, &t5);
- return t1;
- }
-
- union u {int i; char v[3];};
- union u ut;
- typedef union u tunion;
-
- /* Old Style */
- union u
- union_testA(u2, u3, u4, u5)
- union u u2, *u3;
- tunion u4, *u5;
- {
- printf("%p, %p, %p, %p\n", &u2, u3, &u4, u5);
- return ut;
- }
-
- /* New Style */
- union u
- union_testB(
- union u u2,
- union u *u3,
- tunion u4,
- tunion *u5)
- {
- printf("%p, %p, %p, %p\n", &u2, u3, &u4, u5);
- return ut;
- }
-
- /* Old Style with typedefs */
- tunion
- union_testA2(u2, u3, u4, u5)
- tunion u2, *u3;
- union u u4, *u5;
- {
- printf("%p, %p, %p, %p\n", &u2, u3, &u4, u5);
- return ut;
- }
-
- /* New Style with typedefs */
- tunion
- union_testB2(
- tunion u2,
- tunion *u3,
- union u *u4,
- union u u5)
- {
- printf("%p, %p, %p, %p\n", &u2, u3, u4, &u5);
- return ut;
- }
-
- /* ---------------------------------- */
- /*
- /* ---------------------------------- */
-
- /* comment */
-
- void foo()
- {}
-
- typedef unsigned short word;
- typedef struct {
- word st_col; /* starting column of line. */
- word st_row; /* starting row. */
- word end_col; /* ending column. */
- word end_row; /* ending row. */
- word st_arcol; /* starting col of arrorhead. */
- word st_arrow; /* starting row. */
- word end_arcol; /* ending col. */
- word end_arrow; /* ending row. */
- } line;
-
- #define min(a,b) ( ((a) < (b)) ? (a) : (b) )
- #define max(a,b) ( ((a) > (b)) ? (a) : (b) )
-
- extern void generate_line(line *l)
- {
- word min_row_ext, min_col_ext, max_row_ext, max_col_ext;
- min_row_ext = 0;
- min_col_ext = 1;
- max_row_ext = 3;
- max_col_ext = 5;
- min_row_ext = min(min_row_ext, min(l->st_arrow, min(l->end_arrow, min(l->st_row, l->end_row))));
- min_col_ext = min(min_col_ext, min(l->st_arcol, min(l->end_arcol, min(l->st_row, l->end_col))));
- max_row_ext = max(max_row_ext, max(l->st_arrow, max(l->end_arrow, max(l->st_row, l->end_row))));
- max_col_ext = max(max_col_ext, max(l->st_arcol, max(l->end_arcol, max(l->st_row, l->end_col))));
- }
-